﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace DataConsistency.UC
{
    public partial class BieuDo : UserControl
    {
        Para CPara = new Para();

        // Khai bao cac list chua cac do do ket qua
        public List<int> lSoDLThayDoi = new List<int>();
        public List<int> lSoMUAnhHuong = new List<int>();
        public List<double> lNangLuong = new List<double>();
        public List<double> lBandWidth = new List<double>();
        public List<double> lSLYCCN = new List<double>();
        public List<int> lMUMatKetNoi = new List<int>();
        public List<double> lAT = new List<double>();
        public List<double> lATKoLP = new List<double>();
        public List<double> lTT = new List<double>();
        public List<double> lTTKoLP = new List<double>();
        public List<double> lZone = new List<double>();
        public List<double> lOutZone = new List<double>();
        public List<double> lBS = new List<double>();
        public List<double> lSum = new List<double>();
        public List<double> lQueryUpLink = new List<double>();
        public List<double> lTLGoiUplink = new List<double>();
        public List<double> lTLDLMatHopLe = new List<double>();

        List<string[]> kqArr = new List<string[]>();

        /// <summary>
        /// Clear List
        /// </summary>
        public void Init()
        {            
            lSoDLThayDoi.Clear();
            lSoMUAnhHuong.Clear();
            lNangLuong.Clear();
            lBandWidth.Clear();
            lBandWidth.Clear();
            lSLYCCN.Clear();
            lMUMatKetNoi.Clear();
            lAT.Clear();
            lATKoLP.Clear();
            lTT.Clear();
            lTTKoLP.Clear();
            lZone.Clear();
            lOutZone.Clear();
            lBS.Clear();
            lSum.Clear();
            lQueryUpLink.Clear();
            lTLGoiUplink.Clear();
            lTLDLMatHopLe.Clear();
        }
       
        public BieuDo()
        {
            InitializeComponent();
        }

        private void BieuDo_Load(object sender, EventArgs e)
        {
                           
                    
        }

        public void ClearChart()
        {
            ctrlBieuDo.Series.Clear();
            ctrlBieuDo.Titles.Clear();
        }

        public bool checkListMU()
        {
            bool flag = true;
            for (int i = 1; i < lSoMUAnhHuong.Count; i++)
            {
                if (lSoMUAnhHuong[i] != lSoMUAnhHuong[0])
                {
                    flag = false;
                }
            }
            return flag;
        }

        private void btnPath_Click(object sender, EventArgs e)
        {
            Init();// Khoi tao cac list
            ClearChart();

            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            dialog.InitialDirectory = @"C:\test";
            dialog.Title = "Chọn file kết quả";

            if (dialog.ShowDialog() == DialogResult.OK)
            {                
                // Doc file ket qua
                string filePath = dialog.FileName;
                txtPath.Text = filePath;                
                kqArr   = CPara.ReadFile(filePath);
          
                // Lay cac gia tri tu doc file
                 for (int i = 0; i < kqArr.Count(); i++)
                 {
                     string[] Argu = kqArr[i];
              
                     int SoDLThaydoi = int.Parse(Argu[0].ToString());
                     int SLMUAnhHuong = int.Parse(Argu[1].ToString());
                     double NangLuong = double.Parse(Argu[2].ToString());
                     double BandWidth = double.Parse(Argu[3].ToString());
                     double SLYCCN = double.Parse(Argu[4].ToString());
                     int SLMUMatKetNoi = int.Parse(Argu[5].ToString());
                     double AT = double.Parse(Argu[6].ToString());
                     double ATKoLP = double.Parse(Argu[7].ToString());
                     double TT = double.Parse(Argu[8].ToString());
                     double TTKoLP = double.Parse(Argu[9].ToString());
                     double Zone = double.Parse(Argu[10].ToString());
                     double OutZone = double.Parse(Argu[11].ToString());
                     double BS = double.Parse(Argu[12].ToString());
                     double QueryUpLink = double.Parse(Argu[13].ToString());
                     double Sum = Zone + OutZone + BS;
                     double TLGoiUplink = BS / SLYCCN * 100;
                     double TLDLMatHopLe = 100 - TLGoiUplink;

                     lSoDLThayDoi.Add(SoDLThaydoi);
                     lSoMUAnhHuong.Add(SLMUAnhHuong);
                     lNangLuong.Add(NangLuong);
                     lBandWidth.Add(BandWidth);
                     lSLYCCN.Add(SLYCCN);
                     lMUMatKetNoi.Add(SLMUMatKetNoi);
                     lAT.Add(AT);
                     lATKoLP.Add(ATKoLP);
                     lTT.Add(TT);
                     lTTKoLP.Add(TTKoLP);
                     lZone.Add(Zone);
                     lOutZone.Add(OutZone);
                     lBS.Add(BS);
                     lQueryUpLink.Add(QueryUpLink);
                     lSum.Add(Sum);
                     lTLGoiUplink.Add(TLGoiUplink);
                     lTLDLMatHopLe.Add(TLDLMatHopLe);                     
                 }
            }
        }

        
        private void radioAT_CheckedChanged(object sender, EventArgs e)
        {
            if (radioAT.Checked == true)
            {
                ClearChart();
                for (int i = 0; i < lAT.Count; i++)
                {
                    Series sr = new Series();
                    ctrlBieuDo.Series.Add(sr);
                }
                // Ve AT co lich phat
                ChartElement element = ctrlBieuDo.Series.GetElementByIndex(0);
                Series se = (Series)element;
                se.ChangeView(ViewType.Line);
                //se.View.Color = Color.Red;
                se.Points.Clear();
                se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se.PointOptions.PointView = PointView.Undefined;
                se.LegendText = "AT có lịch phát";
                se.ShowInLegend = true;
                for (int i = 0; i < lAT.Count; i++)
                {
                    double p = lAT[i];                                     
                    se.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), p));
                }

                // Ve AT ko LP
                ChartElement element1 = ctrlBieuDo.Series.GetElementByIndex(1);
                Series se1 = (Series)element1;
                se1.ChangeView(ViewType.Line);
                //se.View.Color = Color.Green;
                se1.Points.Clear();
                se1.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se1.PointOptions.PointView = PointView.Undefined;
                se1.LegendText = "AT không lịch phát";
                se1.ShowInLegend = true;
                for (int i = 0; i < lATKoLP.Count; i++)
                {
                    double p = lATKoLP[i];                    
                    se1.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), p));
                }
                #region  ATcu
                // Kiem tra truong hop MU
                /*
                if (checkListMU() == true)
                {
                    // Truong hop so luong MU giong nhau
                    for (int i = 0; i < lAT.Count; i++)
                    {
                        Series sr = new Series();
                        ctrlBieuDo.Series.Add(sr);
                    }
                    for (int i = 0; i < lAT.Count; i++)
                    {
                        ChartElement element = ctrlBieuDo.Series.GetElementByIndex(i);
                        Series se = (Series)element;
                        se.Points.Clear();
                        se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                        se.PointOptions.PointView = PointView.Undefined;
                        se.LegendText = "TH 0" + (i + 1).ToString();
                        se.ShowInLegend = true;
                        double p1 = lAT[i];
                        double p2 = lATKoLP[i];
                        se.Points.Add(new SeriesPoint("AT", p1));
                        se.Points.Add(new SeriesPoint("AT Không LP", p2));
                    }
                }
                else
                {                    
                }
                 */
                #endregion

                //-------- Title -----------------
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "AT có lịch phát";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Thời gian(s)";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;

            }
        }

        private void radioTT_CheckedChanged(object sender, EventArgs e)
        {
            if (radioTT.Checked == true)
            {
                ClearChart();
                // Kiem tra truong hop MU
                if (checkListMU() == true)
                {
                    // Truong hop so luong MU giong nhau
                    for (int i = 0; i < lTT.Count; i++)
                    {
                        Series sr = new Series();
                        ctrlBieuDo.Series.Add(sr);
                    }
                    for (int i = 0; i < lTT.Count; i++)
                    {

                        ChartElement element = ctrlBieuDo.Series.GetElementByIndex(i);
                        Series se = (Series)element;
                        se.Points.Clear();
                        se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                        se.PointOptions.PointView = PointView.Undefined;
                        se.LegendText = "TH 0" + (i + 1).ToString();
                        se.ShowInLegend = true;
                        double p1 = lTT[i];
                        double p2 = lTTKoLP[i];
                        se.Points.Add(new SeriesPoint("TT", p1));
                        se.Points.Add(new SeriesPoint("TT Không LP", p2));

                    }
                }
                else
                {
                    // truong hop so luong MU khac nhau
                    for (int i = 0; i < lTTKoLP.Count; i++)
                    {
                        Series sr = new Series();
                        ctrlBieuDo.Series.Add(sr);
                    }
                    // Ve TT
                    ChartElement element = ctrlBieuDo.Series.GetElementByIndex(0);
                    Series se = (Series)element;
                    se.ChangeView(ViewType.Line);
                    se.Points.Clear();
                    se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                    se.PointOptions.PointView = PointView.Undefined;
                    se.LegendText = "TT";
                    se.ShowInLegend = true;

                    for (int i = 0; i < lTT.Count; i++)
                    {
                        double p = lTT[i];
                        //se.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), p));
                        se.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), p));
                    }
                    // Ve TT ko LP
                    ChartElement element1 = ctrlBieuDo.Series.GetElementByIndex(1);
                    Series se1 = (Series)element1;
                    se1.ChangeView(ViewType.Line);
                    se1.Points.Clear();
                    se1.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                    se1.PointOptions.PointView = PointView.Undefined;
                    se1.LegendText = "TT không lịch phát";
                    se1.ShowInLegend = true;

                    for (int i = 0; i < lTTKoLP.Count; i++)
                    {
                        double p = lTTKoLP[i];
                        //se1.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), p));
                        se1.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), p));
                    }
                }
                //---------- Title -------------
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "TT có lịch phát";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Thời gian(s)";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
            }
        }
        
        /// <summary>
        /// Ty le du lieu mat hop le
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioDLMatHL_CheckedChanged(object sender, EventArgs e)
        {
            if (radioDLMatHL.Checked == true)
            {
                ClearChart();

                Series series1 = new Series("Series 1", ViewType.FullStackedBar);
                series1.LegendText = "Tỉ lệ dữ liệu mất hợp lệ được cập nhật";
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Precision = 1;
                //((FullStackedBarSeriesView)series1.View).BarWidth = 0.4;

                Series series2 = new Series("Series 2", ViewType.FullStackedBar);
                series2.LegendText = "Tỉ lệ dữ liệu mất hợp lệ không được cập nhật";
                ((FullStackedBarPointOptions)series2.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series2.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series2.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series2.PointOptions).ValueNumericOptions.Precision = 1;
                //((FullStackedBarSeriesView)series2.View).BarWidth = 0.4;
                
                //kich ban 1
                /*
                for (int i = 0; i < lTLDLMatHopLe.Count; i++)
                {
                    double x = lQueryUpLink[i];
                    double y = 100.0 - x;                    
                    series1.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), x ));
                    series2.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), y ));
                }
                */

                // Kich ban 3    
            
                for (int i = 0; i < lTLDLMatHopLe.Count; i++)
                {
                    series1.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), lQueryUpLink[i]));
                    series2.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), 100.0 - lQueryUpLink[i] ));
                }                
                
                // Add both series to the chart.                
                ctrlBieuDo.Series.Add(series1);
                ctrlBieuDo.Series.Add(series2);

                //------- Title -----
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "Tỉ lệ dữ liệu mất hợp lệ được cập nhật";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                //diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.Text = "Số lượng MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Phần trăm";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
                diagram.AxisY.NumericOptions.Format = NumericFormat.Percent;
                diagram.AxisY.NumericOptions.Precision = 0;
            }
        }

        /// <summary>
        /// Ho tro dong bo du lieu giua cac MU
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioTyLeHoTro_CheckedChanged(object sender, EventArgs e)
        {
            if (radioTyLeHoTro.Checked == true)
            {   
             
                ClearChart();
                Series series1 = new Series("Series 1", ViewType.FullStackedBar);
                series1.LegendText = "Zone";
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Precision = 1;
                ((FullStackedBarSeriesView)series1.View).BarWidth = 0.4;                

                Series series2 = new Series("Series 2", ViewType.FullStackedBar);
                series2.LegendText = "OutZone";
                ((FullStackedBarPointOptions)series2.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series2.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series2.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series2.PointOptions).ValueNumericOptions.Precision = 1;
                ((FullStackedBarSeriesView)series2.View).BarWidth = 0.4;
                

                Series series3 = new Series("Series 2", ViewType.FullStackedBar);
                series3.LegendText = "BS";
                ((FullStackedBarPointOptions)series3.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series3.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series3.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series3.PointOptions).ValueNumericOptions.Precision = 1;
                ((FullStackedBarSeriesView)series3.View).BarWidth = 0.4;
                

                int soluongdulieu = 0;
                for (int i = 0; i < lZone.Count; i++)
                {
                    double x = lZone[i] ;
                    double y = lOutZone[i];
                    double z = lBS[i];
                    
                    if (i < lZone.Count - 1)
                    {
                        soluongdulieu = soluongdulieu + 50;
                    }
                    else
                    {
                        soluongdulieu = soluongdulieu + 100;
                    }
                    
                    /*
                    series1.Points.Add(new SeriesPoint(soluongdulieu.ToString(), x / (x + y + z) * 100 ));
                    series2.Points.Add(new SeriesPoint(soluongdulieu.ToString(), y / (x + y + z) * 100));
                    series3.Points.Add(new SeriesPoint(soluongdulieu.ToString(), z / (x + y + z) * 100));
                    */
                    
                    // Kich ban 3
                    
                    series1.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), x / (x + y + z) * 100));
                    series2.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), y / (x + y + z) * 100));
                    series3.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), z / (x + y + z) * 100));
                    
                }               

                // Add both series to the chart.                
                ctrlBieuDo.Series.Add(series1);
                ctrlBieuDo.Series.Add(series2);
                ctrlBieuDo.Series.Add(series3);

                //--------- Title -----------
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "Tỉ lệ hỗ trợ đồng bộ giữa các MU";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng MU";
                //diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Phần trăm";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
                diagram.AxisY.NumericOptions.Format = NumericFormat.Percent;
                diagram.AxisY.NumericOptions.Precision = 0;
                
            }
        }

        /// <summary>
        /// Thoi gian truy xuat du lieu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioAT_CheckedChanged_1(object sender, EventArgs e)
        {
            // Ve AT va AT ko lich phat
            if (radioAT.Checked == true)
            {
                ClearChart();// Xoa du lieu cu cua bieu do

                // Add so luong series cho bieu do
                for (int i = 0; i < lAT.Count; i++)
                {
                    Series sr = new Series();
                    ctrlBieuDo.Series.Add(sr);
                }  
                  
                // Ve AT
                ChartElement element = ctrlBieuDo.Series.GetElementByIndex(0);
                Series se = (Series)element;
                se.ChangeView(ViewType.Line);
                //se.View.Color = Color.Red;
                se.Points.Clear();
                se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se.PointOptions.PointView = PointView.Undefined;
                se.LegendText = "AT có lịch phát" ;
                se.ShowInLegend = true;
                for (int i = 0; i < lAT.Count; i++)
                {
                    double p = lAT[i];                          
                    se.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), p));                        
                }

                // Ve AT ko LP
                ChartElement element1 = ctrlBieuDo.Series.GetElementByIndex(1);
                Series se1 = (Series)element1;
                se1.ChangeView(ViewType.Line);
                //se.View.Color = Color.Green;
                se1.Points.Clear();
                se1.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se1.PointOptions.PointView = PointView.Undefined;
                se1.LegendText = "AT không lịch phát";
                se1.ShowInLegend = true;
                for (int i = 0; i < lATKoLP.Count; i++)
                {
                    double p = lATKoLP[i];                
                    se1.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), p));
                }                   
              
                //-------- Title -----------------
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "Thời gian truy xuất dữ liệu (AT)";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Thời gian(s)";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;

            }
        }

        /// <summary>
        /// Thoi gian nhan du lieu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioTT_CheckedChanged_1(object sender, EventArgs e)
        {
            if (radioTT.Checked == true)
            {
                ClearChart();
                // Add series vao bieu do
                for (int i = 0; i < lTTKoLP.Count; i++)
                {
                    Series sr = new Series();
                    ctrlBieuDo.Series.Add(sr);
                }
                
                // Ve TT
                ChartElement element = ctrlBieuDo.Series.GetElementByIndex(0);
                Series se = (Series)element;
                se.ChangeView(ViewType.Line);
                se.Points.Clear();
                se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se.PointOptions.PointView = PointView.Undefined;
                se.LegendText = "TT có lịch phát";
                se.ShowInLegend = true;

                for (int i = 0; i < lTT.Count; i++)
                {
                    double p = lTT[i];                    
                    se.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), p));
                }
                // Ve TT ko LP
                ChartElement element1 = ctrlBieuDo.Series.GetElementByIndex(1);
                Series se1 = (Series)element1;
                se1.ChangeView(ViewType.Line);
                se1.Points.Clear();
                se1.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se1.PointOptions.PointView = PointView.Undefined;
                se1.LegendText = "TT không lịch phát";
                se1.ShowInLegend = true;

                for (int i = 0; i < lTTKoLP.Count; i++)
                {
                    double p = lTTKoLP[i];                    
                    se1.Points.Add(new SeriesPoint(lSoDLThayDoi[i].ToString(), p));
                }

                #region kich ban 3
                // Kich ban 3
                /*
                // Ve TT
                ChartElement element = ctrlBieuDo.Series.GetElementByIndex(0);
                Series se = (Series)element;
                se.ChangeView(ViewType.Line);
                se.Points.Clear();
                se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se.PointOptions.PointView = PointView.Undefined;
                se.LegendText = "Thời gian nhận dữ liệu TT";
                se.ShowInLegend = true;

                for (int i = 0; i < lTT.Count; i++)
                {
                    double p = lTT[i];
                    se.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), p));
                }
                */
                #endregion

                //---------- Title -------------
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "Thời gian nhận dữ liệu (TT)";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Thời gian(s)";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
            }           
        }

        private void radioTyleHoTro2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioTyleHoTro2.Checked == true)
            {

                ClearChart();
                Series series1 = new Series("Series 1", ViewType.FullStackedBar);
                series1.LegendText = "Vùng cộng tác";
                //series1.LegendText = "Tỷ lệ dữ liệu mất hợp lệ được cập nhật";
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Precision = 1;
                ((FullStackedBarSeriesView)series1.View).BarWidth = 0.4;

                Series series3 = new Series("Series 2", ViewType.FullStackedBar);
                series3.LegendText = "BS";
                //series3.LegendText = "Tỷ lệ dữ liệu mất hợp lệ không được cập nhật";
                ((FullStackedBarPointOptions)series3.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series3.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series3.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series3.PointOptions).ValueNumericOptions.Precision = 1;
                ((FullStackedBarSeriesView)series3.View).BarWidth = 0.4;

                int soluongdulieu = 0;
                for (int i = 0; i < lZone.Count; i++)
                {
                    double x = lZone[i];
                    double y = lOutZone[i];
                    double z = lBS[i];

                    if (i < lZone.Count - 1)
                    {
                        soluongdulieu = soluongdulieu + 50;
                    }
                    else
                    {
                        soluongdulieu = soluongdulieu + 100;
                    }
                    
                    //Kich ban 2
                    //series1.Points.Add(new SeriesPoint(soluongdulieu.ToString(), (x + y) / (x + y + z) * 100));                    
                    //series3.Points.Add(new SeriesPoint(soluongdulieu.ToString(), z / (x + y + z) * 100));
                    
                    // ty le cap nhat
                    /*
                    double m = lTLGoiUplink[i];
                    double n = 100.00 - m;
                    //MessageBox.Show(m.ToString());
                    series1.Points.Add(new SeriesPoint(soluongdulieu.ToString(), n));
                    series3.Points.Add(new SeriesPoint(soluongdulieu.ToString(), m));
                    */

                    //Kich ban 3
                    double m = (x + y) / (x + y + z) * 100;
                    double n = 100.0 - m;
                    //MessageBox.Show(n.ToString());
                    series1.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), m));                    
                    series3.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(),  n));
                    
                }

                // Add both series to the chart.                
                ctrlBieuDo.Series.Add(series1);                
                ctrlBieuDo.Series.Add(series3);

                //--------- Title -----------
                ChartTitle ctt = new ChartTitle();
                //ctt.Text = "Tỉ lệ hỗ trợ đồng bộ giữa các MU";
                ctt.Text = "Tỉ lệ dữ liệu mất hợp lệ được cập nhật";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng MU";
                //diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Phần trăm";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
                diagram.AxisY.NumericOptions.Format = NumericFormat.Percent;
                diagram.AxisY.NumericOptions.Precision = 1;
                //diagram.AxisY.Range.MinValueInternal = 95;
                //diagram.AxisY.Range.MinValueInternal = 100;
            }
        }

        private void radioDLmathople2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioDLmathople2.Checked == true)
            {
                ClearChart();

                Series series1 = new Series("Series 1", ViewType.FullStackedBar);
                series1.LegendText = "Tỉ lệ dữ liệu mất hợp lệ được cập nhật";
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Precision = 1;
                ((FullStackedBarSeriesView)series1.View).BarWidth = 0.4;

                Series series2 = new Series("Series 2", ViewType.FullStackedBar);
                series2.LegendText = "Tỉ lệ dữ liệu mất hợp lệ không được cập nhật";
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.ValueAsPercent = true;
                ((FullStackedBarPointOptions)series1.PointOptions).PercentOptions.PercentageAccuracy = 4;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((FullStackedBarPointOptions)series1.PointOptions).ValueNumericOptions.Precision = 1;
                ((FullStackedBarSeriesView)series1.View).BarWidth = 0.4;

                int soluongdulieu = 0;
                for (int i = 0; i < lTLDLMatHopLe.Count; i++)
                {
                    if (i < lTLDLMatHopLe.Count - 1)
                    {
                        soluongdulieu = soluongdulieu + 50;
                    }
                    else
                    {
                        soluongdulieu = soluongdulieu + 100;
                    }                    
                    series1.Points.Add(new SeriesPoint(soluongdulieu.ToString(), lTLDLMatHopLe[i]));
                    series2.Points.Add(new SeriesPoint(soluongdulieu.ToString(), lTLGoiUplink[i]));
                }

                // Access the view-type-specific options of the series.
                //((FullStackedBarSeriesView)series1.View).BarWidth = 0.4;
                //((FullStackedBarSeriesView)series2.View).BarWidth = 0.4;

                // Add both series to the chart.                
                ctrlBieuDo.Series.Add(series1);
                ctrlBieuDo.Series.Add(series2);

                //------- Title -----
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "Tỉ lệ dữ liệu mất hợp lệ được cập nhật";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Phần trăm";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
                
            }
        }

        private void radioTyleguiuplink_CheckedChanged(object sender, EventArgs e)
        {
            if (radioTyleguiuplink.Checked == true)
            {
                ClearChart();// Xoa du lieu cu cua bieu do

                // Add so luong series cho bieu do
                for (int i = 0; i < lTLGoiUplink.Count; i++)
                {
                    Series sr = new Series();
                    ctrlBieuDo.Series.Add(sr);
                }

                // Ve AT
                ChartElement element = ctrlBieuDo.Series.GetElementByIndex(0);
                Series se = (Series)element;
                se.ChangeView(ViewType.Line);
                se.Points.Clear();
                se.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                se.PointOptions.PointView = PointView.Undefined;
                se.LegendText = "Tỉ lệ gửi yêu cầu lên kênh Uplink";
                se.ShowInLegend = true;
                
                int soluongdulieu = 0;
                for (int i = 0; i < lTLGoiUplink.Count; i++)
                {
                    if (i < lTLGoiUplink.Count - 1)
                    {
                        soluongdulieu = soluongdulieu + 50;
                    }
                    else
                    {
                        soluongdulieu = soluongdulieu + 100;
                    }
                    double p = (100.0 - lQueryUpLink[i])/100;                   
                    //se.Points.Add(new SeriesPoint(soluongdulieu.ToString(), p));
                    se.Points.Add(new SeriesPoint(lSoMUAnhHuong[i].ToString(), p));
                }

                //-------- Title -----------------
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "Tỉ lệ gửi yêu cầu lên kênh Uplink";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                //diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.Text = "Số lượng MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Phần trăm";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
                diagram.AxisY.NumericOptions.Format = NumericFormat.Percent;
                diagram.AxisY.NumericOptions.Precision = 1;
            }
        }

        private void radioATCo_CheckedChanged(object sender, EventArgs e)
        {
             // Ve AT mat ket noi va ko mat ket noi
            if (radioATCo.Checked == true)
            {
                ClearChart();// Xoa du lieu cu cua bieu do

                // Add so luong series cho bieu do
                for (int i = 0; i < lAT.Count; i++)
                {
                    Series sr = new Series();
                    ctrlBieuDo.Series.Add(sr);
                }
                /*
                // Mat ket noi
                ChartElement element = ctrlBieuDo.Series.GetElementByIndex(0);
                Series se = (Series)element;
                se.ChangeView(ViewType.Line);
                //se.View.Color = Color.Red;
                se.Points.Clear();
                se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se.PointOptions.PointView = PointView.Undefined;
                se.LegendText = "Có mất kết nối";
                se.ShowInLegend = true;
                int soluongdulieuAT = 0;
                for (int i = 0; i < lAT.Count; i++)
                {
                    if (i < lTLDLMatHopLe.Count - 1)
                    {
                        soluongdulieuAT = soluongdulieuAT + 50;
                    }
                    else
                    {
                        soluongdulieuAT = soluongdulieuAT + 100;
                    }
                    double p = lAT[i];
                    se.Points.Add(new SeriesPoint(soluongdulieuAT.ToString(), p));
                }
                */

                // Khong mat ket noi
                ChartElement element1 = ctrlBieuDo.Series.GetElementByIndex(1);
                Series se1 = (Series)element1;
                se1.ChangeView(ViewType.Line);
                //se.View.Color = Color.Green;
                se1.Points.Clear();
                se1.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se1.PointOptions.PointView = PointView.Undefined;
                se1.LegendText = "Không mất kết nối";
                se1.ShowInLegend = true;
                int soluongdulieu = 0;
                for (int i = 0; i < lATKoLP.Count; i++)
                {
                    if (i < lAT.Count - 1)
                    {
                        soluongdulieu = soluongdulieu + 50;
                    }
                    else
                    {
                        soluongdulieu = soluongdulieu + 100;
                    }
                    double p = lATKoLP[i];
                    se1.Points.Add(new SeriesPoint(soluongdulieu.ToString(), p));
                }                

                //-------- Title -----------------
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "AT có lịch phát";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Thời gian(s)";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
            }
        }

        private void radioTTCo_CheckedChanged(object sender, EventArgs e)
        {
             // Ve AT mat ket noi va ko mat ket noi
            if (radioTTCo.Checked == true)
            {
                ClearChart();// Xoa du lieu cu cua bieu do

                // Add so luong series cho bieu do
                for (int i = 0; i < lTT.Count; i++)
                {
                    Series sr = new Series();
                    ctrlBieuDo.Series.Add(sr);
                }
                /*
                // Mat ket noi
                ChartElement element = ctrlBieuDo.Series.GetElementByIndex(0);
                Series se = (Series)element;
                se.ChangeView(ViewType.Line);
                //se.View.Color = Color.Red;
                se.Points.Clear();
                se.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se.PointOptions.PointView = PointView.Undefined;
                se.LegendText = "Có mất kết nối";
                se.ShowInLegend = true;
                int soluongdulieuTT = 0;
                for (int i = 0; i < lTT.Count; i++)
                {
                    if (i < lTT.Count - 1)
                    {
                        soluongdulieuTT = soluongdulieuTT + 50;
                    }
                    else
                    {
                        soluongdulieuTT = soluongdulieuTT + 100;
                    }
                    double p = lTT[i];
                    se.Points.Add(new SeriesPoint(soluongdulieuTT.ToString(), p));
                }
                */

                // Khong mat ket noi
                ChartElement element1 = ctrlBieuDo.Series.GetElementByIndex(1);
                Series se1 = (Series)element1;
                se1.ChangeView(ViewType.Line);
                //se.View.Color = Color.Green;
                se1.Points.Clear();
                se1.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
                se1.PointOptions.PointView = PointView.Undefined;
                se1.LegendText = "Không mất kết nối";
                se1.ShowInLegend = true;
                int soluongdulieu = 0;
                for (int i = 0; i < lTTKoLP.Count; i++)
                {
                    if (i < lTTKoLP.Count - 1)
                    {
                        soluongdulieu = soluongdulieu + 50;
                    }
                    else
                    {
                        soluongdulieu = soluongdulieu + 100;
                    }
                    double p = lTTKoLP[i];
                    se1.Points.Add(new SeriesPoint(soluongdulieu.ToString(), p));
                }
                

                //-------- Title -----------------
                ChartTitle ctt = new ChartTitle();
                ctt.Text = "TT có lịch phát";
                ctt.TextColor = Color.Orange;
                ctt.Font = new Font("Times New Roman", 18, FontStyle.Bold);
                ctrlBieuDo.Titles.Add(ctt);

                XYDiagram diagram = (XYDiagram)ctrlBieuDo.Diagram;
                diagram.AxisX.Title.Visible = true;
                diagram.AxisX.Title.Text = "Số lượng đơn vị dữ liệu ở MU";
                diagram.AxisX.Title.TextColor = Color.Red;
                diagram.AxisX.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);

                diagram.AxisY.Title.Visible = true;
                diagram.AxisY.Title.TextColor = Color.Red;
                diagram.AxisY.Title.Font = new Font("Times New Roman", 12, FontStyle.Bold);
                diagram.AxisY.Title.Text = "Thời gian(s)";
                diagram.AxisY.Title.Alignment = StringAlignment.Far;
            }
        }
    }
}
